//
//  CardMsgCell.m
//  ChangChat
//
//  Created by Cocoa on 2019/8/22.
//  Copyright © 2019 yibai. All rights reserved.
//

#import "CardMsgCell.h"

@implementation CardMsgCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
        
    }
    return self;
}
- (void)setupUI {
    
    self.cardIconImgView = [UIImageView new];
    self.cardNicknameLabel = [UILabel k_labelWithFontSize:15 textColor:UIColor.k_t2Color];
    self.cardDescLabel = [UILabel k_labelWithFontSize:13 textColor:UIColor.k_t3Color];
    
    UIView *lineView = [UIView new];
    lineView.backgroundColor = global_view_darkLineColor;
    UILabel *bottomLabel = [UILabel k_labelWithFontSize:10 textColor:UIColor.k_t3Color];
    bottomLabel.text = @"个人名片";
    
    [self.msgContentView addSubview:self.cardIconImgView];
    [self.msgContentView addSubview:self.cardNicknameLabel];
    [self.msgContentView addSubview:self.cardDescLabel];
    [self.msgContentView addSubview:lineView];
    [self.msgContentView addSubview:bottomLabel];
    self.msgContentView.backgroundColor = UIColor.k_hexColor(0xf7f7f7);
    
    [self.cardIconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_offset(Chat_MsgContent_Padding);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    self.cardIconImgView.layer.cornerRadius = 20;
    self.cardIconImgView.layer.masksToBounds = YES;
    
    [self.cardNicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cardIconImgView);
        make.left.equalTo(self.cardIconImgView.mas_right).offset(5);
        make.right.mas_offset(-Chat_MsgContent_Padding);
    }];
    [self.cardDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cardNicknameLabel);
        make.top.equalTo(self.cardNicknameLabel.mas_bottom).offset(5);
        make.right.equalTo(self.cardNicknameLabel);
    }];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cardIconImgView);
        make.right.equalTo(self.cardNicknameLabel);
        make.top.equalTo(self.cardIconImgView.mas_bottom).offset(10);
        make.height.mas_equalTo(1.0f);
    }];
    
    [bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lineView);
        make.top.equalTo(lineView.mas_bottom).offset(5);
        make.bottom.mas_offset(-5);
    }];
    
    [self.msgContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(Chat_MsgContent_MaxWidth * 4/5);
    }];
    
    
    self.cardIconImgView.image = UIImage.k_imgName(@"placeholder_user");
    self.cardNicknameLabel.text = @"李四";
    self.cardDescLabel.text = @"18866668888";
}

- (void)setMsgModel:(MsgModel *)msgModel {
    [super setMsgModel:msgModel];
    MsgItem *item = msgModel.msg;
    FriendItem *user = [FriendItem mj_objectWithKeyValues:item.content];
    [self.cardIconImgView sd_setImageWithURL:user.avatar.toURL placeholderImage:UIImage.k_imgName(@"placeholder_user")];
    self.cardNicknameLabel.text = user.username;
    self.cardDescLabel.text = [NSString stringWithFormat:@"ID: %@", user.ID];
}

@end
